from rocketmq.client import Producer, Message
import json


producer = Producer('PID-dev')
producer.set_namesrv_addr('rocket-dev.bnq.in:9876')  # rocketmq队列接口地址（服务器ip:port）
producer.start()

topic_name = "ship_order"
keys = "0319193042"
tags = "confirm"
msg_body = {"id": "001", "name": "test_mq", "message": "abcdefg"}
ss = json.dumps(msg_body).encode('utf-8')

msg = Message(topic_name)  # topic名称
msg.set_keys(keys)
msg.set_tags(tags)
msg.set_body(ss)  # message body

retmq = producer.send_sync(msg)
assert (retmq.status, "SendStatus.OK")
print(retmq.status, retmq.msg_id, retmq.offset)

producer.shutdown()
